package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    @Insert("insert into orders (number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number, tableware_status) " + "values(#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod},\n" + "                #{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{consignee},\n" + "                #{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Orders orders);

    Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id=#{id}")
    Orders getByid(Long id);

    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String outTradeNo);

    void update(Orders orders);

    @Select("select count(orders.id) from orders where status=#{status}")
    Integer getstatus(Integer toBeConfirmed);

    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> selectOvertimeorders(Integer status, LocalDateTime orderTime);

    

    @Select("select COUNT(*) from orders")
    Integer getAllOrders();

    Double sumBymap(Map map);

    Integer CountByMap(Map map);


    List<GoodsSalesDTO> getSalesTop10();

    Integer countByMap(Map map);

    Double sumByMap(Map map);
}
